use actix_http::StatusCode;
use actix_web::{HttpResponse, HttpResponseBuilder};
use serde::Serialize;
use wither::bson::Document;

use crate::models::{account::AccountModel, user::UserModel};

pub trait ToJsonResponse: Serialize {
    fn status(&self) -> StatusCode {
        StatusCode::OK
    }

    fn to_json_response(&self) -> HttpResponse {
        HttpResponseBuilder::new(self.status()).json(self)
    }
}

pub trait ToUserInfo {
    fn to_user_info(&self) -> UserModel;
}
pub trait ToSearchDoc {
    fn to_search_doc(&self) -> Document;
}
pub trait ToUpdateDoc {
    fn to_update_doc(&self) -> Document;
}
pub trait ToAccountModel {
    fn to_account_model(&self) -> AccountModel;
}
/// 当数据被更改时的额外处理特性
pub trait ModifyModelData {
    /// 数据发生更改
    fn modifyed(&mut self);
}
pub trait UpdateModelData {
    type Error;
    fn get_update_set_doc(&self) -> Result<Document, Self::Error>;
    fn get_update_filter_doc(&self) -> Result<Document, Self::Error>;
}
